// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//
#include <pollux/functions/registerer.h>
#include <pollux/functions/prestosql/binary_functions.h>

namespace kumo::pollux::functions {
    namespace {
        void registerSimpleFunctions(const std::string &prefix) {
            // Register hash functions.
            register_function<CRC32Function, int64_t, Varbinary>({prefix + "crc32"});
            register_function<XxHash64Function, Varbinary, Varbinary>(
                {prefix + "xxhash64"});
            register_function<Md5Function, Varbinary, Varbinary>({prefix + "md5"});
            register_function<Murmur3X64_128Function, Varbinary, Varbinary>(
                {prefix + "murmur3_x64_128"});
            register_function<Sha1Function, Varbinary, Varbinary>({prefix + "sha1"});
            register_function<Sha256Function, Varbinary, Varbinary>({prefix + "sha256"});
            register_function<Sha512Function, Varbinary, Varbinary>({prefix + "sha512"});
            register_function<HmacSha1Function, Varbinary, Varbinary, Varbinary>(
                {prefix + "hmac_sha1"});
            register_function<HmacSha256Function, Varbinary, Varbinary, Varbinary>(
                {prefix + "hmac_sha256"});
            register_function<HmacSha512Function, Varbinary, Varbinary, Varbinary>(
                {prefix + "hmac_sha512"});
            register_function<HmacMd5Function, Varbinary, Varbinary, Varbinary>(
                {prefix + "hmac_md5"});
            register_function<SpookyHashV232Function, Varbinary, Varbinary>(
                {prefix + "spooky_hash_v2_32"});
            register_function<SpookyHashV264Function, Varbinary, Varbinary>(
                {prefix + "spooky_hash_v2_64"});

            register_function<ToHexFunction, Varchar, Varbinary>({prefix + "to_hex"});
            register_function<FromHexFunction, Varbinary, Varchar>({prefix + "from_hex"});
            register_function<ToBase64Function, Varchar, Varbinary>(
                {prefix + "to_base64"});

            register_function<FromBase64Function, Varbinary, Varchar>(
                {prefix + "from_base64"});
            register_function<FromBase64Function, Varbinary, Varbinary>(
                {prefix + "from_base64"});

            register_function<ToBase64UrlFunction, Varchar, Varbinary>(
                {prefix + "to_base64url"});
            register_function<FromBase64UrlFunction, Varbinary, Varchar>(
                {prefix + "from_base64url"});

            register_function<FromBigEndian32, int32_t, Varbinary>(
                {prefix + "from_big_endian_32"});
            register_function<ToBigEndian32, Varbinary, int32_t>(
                {prefix + "to_big_endian_32"});
            register_function<FromBigEndian64, int64_t, Varbinary>(
                {prefix + "from_big_endian_64"});
            register_function<ToBigEndian64, Varbinary, int64_t>(
                {prefix + "to_big_endian_64"});
            register_function<ToIEEE754Bits64, Varbinary, double>(
                {prefix + "to_ieee754_64"});
            register_function<FromIEEE754Bits64, double, Varbinary>(
                {prefix + "from_ieee754_64"});
            register_function<ToIEEE754Bits32, Varbinary, float>(
                {prefix + "to_ieee754_32"});
            register_function<FromIEEE754Bits32, float, Varbinary>(
                {prefix + "from_ieee754_32"});
            register_function<
                LPadVarbinaryFunction,
                Varbinary,
                Varbinary,
                int64_t,
                Varbinary>({prefix + "lpad"});
            register_function<
                RPadVarbinaryFunction,
                Varbinary,
                Varbinary,
                int64_t,
                Varbinary>({prefix + "rpad"});
        }
    } // namespace

    void registerBinaryFunctions(const std::string &prefix) {
        registerSimpleFunctions(prefix);
    }
} // namespace kumo::pollux::functions
